function calcEntitiesHitByShot(shot, entity) {
    var allEntities = findAllEntities();

    var entitiesHitByShot = new Array();
    for (var i = 0; i < allEntities.length; i++) {
        if (entity.name === allEntities[i].name) {
            continue;
        }

        var distance = pointToLineSegmentDistance(entity.pos, entity.pos.add(shot), allEntities[i].pos);
        if (distance < 20.0) {
            entitiesHitByShot[entitiesHitByShot.length] = allEntities[i];
        }
    }
    return entitiesHitByShot;
}

/*
 * WARNUNG!!!! not in used yet
 */
var shotRange = 100.0;

function calcShot(entity) {
    var endPointByX = calcEndPointByX(entity);
    var endPointByY = calcEndPointByY(entity);
    var endVectorByX = endPointByX.subtract(entity.pos);
    var endVectorByY = endPointByY.subtract(entity.pos);
    if (endVectorByX.norm() < endVectorByY.norm()) {
        return endVectorByX;
    } else {
        return endVectorByY;
    }
}

function calcEndPointByX(entity) {
    var maxEndOfShot = entity.pos.add(calcMaxShot(entity));
    var startCoords = getTileCoords(entity.pos);
    var endCoords = getTileCoords(maxEndOfShot);
    var delta = signum(endCoords.x - startCoords.x);
    for (var i = startCoords.x; i !== endCoords.x; i += delta) {
        var border = intersectLineWithHorizontalGridBorder(entity.pos, maxEndOfShot, i, delta);
        var adjacentCenter = border.add(new Vector(delta * getTileSize() / 2, 0));
        if (!tileMap.isPassable(getTileCoords(adjacentCenter))) {
            return border;
        }
    }
    return maxEndOfShot;
}

function calcEndPointByY(entity) {
    var maxEndOfShot = entity.pos.add(calcMaxShot(entity));
    var startCoords = getTileCoords(entity.pos);
    var endCoords = getTileCoords(maxEndOfShot);
    var delta = signum(endCoords.y - startCoords.y);
    for (var i = startCoords.y; i !== endCoords.y; i += delta) {
        var border = intersectLineWithVerticalGridBorder(entity.pos, maxEndOfShot, i, delta);
        var adjacentCenter = border.add(new Vector(0, delta * getTileSize() / 2));
        if (!tileMap.isPassable(tileMap.getTileCoords(adjacentCenter))) {
            return border;
        }
    }
    return maxEndOfShot;
}

function calcMaxShot(entity) {
    return new Vector(Math.round(shotRange * Math.cos(entity.angle) * getTileCount()),
            Math.round(shotRange * Math.sin(entity.angle) * getTileCount()));
}

function intersectLineWithHorizontalGridBorder(start, end, gridX, delta) {
    var rightGridX = Math.max(gridX, gridX + delta);
    var borderX = rightGridX * getTileSize();
    if (delta < 0) {
        borderX--;
    }
    var diffX = borderX - start.x;
    var totalX = end.x - start.x;
    var totalY = end.y - start.y;
    var diffY = ((diffX / totalX) * totalY);
    return start.add(new Vector(diffX, diffY));
}

function intersectLineWithVerticalGridBorder(start, end, gridY, delta) {
    var bottomGridY = Math.max(gridY, gridY + delta);
    var borderY = bottomGridY * getTileSize();
    if (delta < 0) {
        borderY--;
    }
    var diffY = borderY - start.y;
    var totalX = end.x - start.x;
    var totalY = end.y - start.y;
    var diffX = ((diffY / totalY) * totalX);
    return start.add(new Vector(diffX, diffY));
}